import {
  CHANGE_INPUT,
  ADD_ITEM,
  DELETE_ITEM,
  GET_LIST,
  GET_MY_LIST,
} from "./actionTypes";
import axios from "axios";
import store from "./index";

export const changeInputAction = (value) => ({
  type: CHANGE_INPUT,
  value,
});

export const addItemAction = () => ({
  type: ADD_ITEM,
});

export const deleteItemAction = (value) => ({
  type: DELETE_ITEM,
  value,
});

export const getListAction = (value) => ({
  type: GET_LIST,
  value,
});

export const getTodoList = () => {
  return (dispatch) => {
    axios
      .get("https://mock.apifox.cn/m1/1695860-0-default/todo/list")
      .then((res) => {
        const data = res.data.data;
        const action = getListAction(data);
        dispatch(action);
      });
  };
};

export const getMyListAction = () => {
  return {
    type: GET_MY_LIST,
  };
};
